$(function () {
    var chart = Highcharts.chart('container',{
        chart: {
            type: 'column'
        },
        title: {
            text: ''
        },
        xAxis: {
            categories: []
        },
        series: [{
            name: '占股',
            data: []
        }]
    });

    // 点击对外投资公司
    $(".sharesContent_left_t_c").on('click','div',function () {
        $("#outboundInvestment").val($(this).attr('id'));
        $("#shareholderId").val($(this).attr('id'));
        $(this).css({'background':'url("https://pynnn.oss-cn-hangzhou.aliyuncs.com/an02.png") no-repeat','background-size':'100% 100%'}).siblings().css({'background':'url("https://pynnn.oss-cn-hangzhou.aliyuncs.com/an01.png") no-repeat','background-size':'100% 100%'})
        $(".sharesContent_right_t_c").find('div').css({'color':'white'});
        $.ajax({
            url: Feng.ctxPath + "/sharesAreCompany/getShareSareRelationInfo",
            type: "post",
            data: {
                "id": $("#outboundInvestment").val()
            },
            success: function (data) {
                var categories = [];
                var seriesData = [];
                for(var i = 0 ; i < data.length ; i++){
                    seriesData.push(data[i].shareholding);
                    categories.push(data[i].account);
                }
                chart.update({
                    series: [{data: seriesData}]
                });
                chart.xAxis[0].update({
                    categories: categories
                })
            },
            error: function (data) {
                alert('没有权限，请联系管理员!');
            }
        });
    });

    // 点击分支机构公司
    $(".sharesContent_right_t_c").on('click','div',function () {
        $("#outboundBranch").val($(this).attr('id'));
        $("#shareholderId").val($(this).attr('id'));
        $(this).css({'color':'rgb(228,244,6)'}).siblings().css({'color':'white'});
        $(".sharesContent_left_t_c").find('.foreignBack_ground').css({'background':'url("https://pynnn.oss-cn-hangzhou.aliyuncs.com/an01.png") no-repeat','background-size':'100% 100%'});
        $.ajax({
            url: Feng.ctxPath + "/sharesAreCompany/getShareSareRelationInfo",
            type: "post",
            data: {
                "id": $("#outboundBranch").val()
            },
            success: function (data) {
                var categories = [];
                var seriesData = [];
                for(var i = 0 ; i < data.length ; i++){
                    seriesData.push(data[i].shareholding);
                    categories.push(data[i].account);
                }
                chart.update({
                    series: [{data: seriesData}]
                });
                chart.xAxis[0].update({
                    categories: categories
                })
            },
            error: function (data) {
                alert('没有权限，请联系管理员!');
            }
        });
    });

    $("#sharesContent_left_t_c > div").eq(0).click();
});


// 点击添加分支机构按钮
$("#branch_a_cancel").click(function () {
    $("#outboundBranch").val("");
    $(".sharesContent_right_t").hide();
    $(".sharesContent_right_m").hide();
    $(".sharesContent_right_b").show();
    $(".sharesContent_right_t_c").find('div').css({'color':'white'})
});

// 返回初始分支机构
$("#branch_btn_cancel,#branch_btn_cancel_modify,#branch_btn_cancel_delete").click(function () {
    $(".sharesContent_right_m").hide();
    $(".sharesContent_right_t").show();
    $(".sharesContent_right_t_c").find('div').css({'color':'white'});
    $(".sharesContent_right_b").hide().find(".sharesContent_branch_input").val("");
    $("#outboundBranch").val("");
});


// 点击添加对外投资按钮
$("#investment_cancel").click(function () {
    $("#outboundInvestment").val("");
    $(".sharesContent_left_t").hide();
    $(".sharesContent_left_h").show();
    $(".sharesContent_left_m").hide();
    $(".sharesContent_left_t_c").find('.foreignBack_ground').css({'background':'url("https://pynnn.oss-cn-hangzhou.aliyuncs.com/an01.png") no-repeat','background-size':'100% 100%'});
});

// 返回初始对外投资
$("#investment_btn_cancel,#investment_modify_cancel").click(function () {
    $(".sharesContent_left_t").show();
    $(".sharesContent_left_h").hide();
    $(".sharesContent_left_m").hide();
    $("#outboundInvestment").val("");
});

function decimalNumTwo(obj) {
    obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
    obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字
    obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
    if (obj.value == "" || obj.value == undefined) {
        obj.value = 0
    }
    if (obj.value.indexOf(".") < 0 && obj.value != "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        obj.value = parseFloat(obj.value);
    }
}